//https://leetcode-cn.com/problems/reverse-only-letters/
package main

import "fmt"

/**
双指针
*/
func reverseOnlyLetters(s string) string {
	isChar := func(c byte) bool {
		return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')
	}
	l, r := 0, len(s)-1
	array := []byte(s)
	for l < r {
		if !isChar(array[l]) {
			l++
		} else if !isChar(array[r]) {
			r--
		} else {
			array[l], array[r] = array[r], array[l]
			l++
			r--
		}
	}
	return string(array)
}

func main() {
	fmt.Println(reverseOnlyLetters("-a") == "-a")
	fmt.Println(reverseOnlyLetters("-") == "-")
	fmt.Println(reverseOnlyLetters("a-bC-dEf-ghIj") == "j-Ih-gfE-dCba")
	fmt.Println(reverseOnlyLetters("ab-cd") == "dc-ba")
	fmt.Println(reverseOnlyLetters("Test1ng-Leet=code-Q!") == "Qedo1ct-eeLg=ntse-T!")
}
